<%@page import="com.demoweb.model.dto.BoardComment"%>
<%@page import="com.demoweb.model.dto.Membership"%>
<%@page import="com.demoweb.model.dto.Board"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8" session="true"%>

<%!String isCommentEditable(Membership member, String writer) {	

	//Member member = (Member)session.getAttribute("loginuser");
	if (member == null) return "none";
	
	if (member.getMemberId().equals(writer))
		return "block";
	else
		return "none";
}%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>FLAPPY FISH</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link href="/demoweb/styles/flappystyle.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
	function doDelete(boardno) {
		var ok = confirm("게시물을 삭제 합니다.");
		if (ok) {
			//삭제 처리
			location.href="delete.action?boardno=" + boardno;
		}
	}
	
	function deleteComment(commentNo, boardNo, pageNo) {
		if (confirm(commentNo + "번 댓글을 삭제할까요?")) {
			location.href='deletecomment.action?commentno=' 
				+ commentNo + "&boardno=" + boardNo + "&pageno=" + pageNo;
		}
	}
	
	function toggleCommentStatus(commentNo, edit) {		
		document.getElementById('commentview' + commentNo).style.display = edit ? 'none' : 'block';
		document.getElementById('commentedit' + commentNo).style.display = edit ? 'block' : 'none';
	}
	
	</script>
</head>
<body>

<%	pageContext.include("/WEB-INF/views/flappy/header.jsp");%>

<div id="content"><!--  style="width: 1024px" -->
  <!-- ---------------------------------- Main page content ----------------------------------- -->
  <div id="sidebar">
      <% pageContext.include("/WEB-INF/views/flappy/flappylogin.jsp"); %>
    <% pageContext.include("/WEB-INF/views/flappy/board/boardmenu.jsp"); %>
  </div>
  
  <div id="main" style="width: 480px; margin-left: 50px; margin-top: 100px"> 
 	<link rel="Stylesheet" href="/demoweb/styles/input.css" /> 
	<div id="pageContainer">	
		<div style="padding-top:25px;text-align:center;">
		<div id="inputcontent">
		    <div id="inputmain">
		    <h2 class="title">자유 게시판</h2>
		        <div class="inputsubtitle">게시판 글 내용</div>
		        <%
		        	Board board = (Board)request.getAttribute("board");
		        %>
		        <table>
		            <tr>
		                <th>제목</th>
		                <td><%=board.getTitle()%></td>
		            </tr>
		            <tr>
		                <th>작성자</th>
		                <td><%=board.getWriter()%></td>
		            </tr>
		            <tr>
		                <th>작성일</th>
		                <td><%=board.getRegDate()%></td>
		            </tr>
					<tr>
		                <th>조회수</th>
		                <td><%=board.getReadCount()%></td>
		            </tr>
		            <tr>
		                <th>내용</th>
		                <td style="height:200px;vertical-align:top">		                    
		                    <%=board.getContent().replace("\r\n", "<br />")%>
		                </td>
		            </tr>
		        </table>
		        <div class="buttons">
		        	<%
		        		String pageNo = request.getParameter("pageno");
		        			        		if (pageNo == null || pageNo.length() == 0)
		        			        			pageNo = "1";
		        	%>
		        	<%
		        		Membership member = (Membership)session.getAttribute("loginuser");
		        	%>
		        	<% if (member.getMemberId().equals(board.getWriter())) { %>
		        	[&nbsp;<a href="editform.action?boardno=<%= board.getBoardNo() %>&pageno=<%= pageNo %>">편집</a>&nbsp;]
		        	[&nbsp;<a href="javascript:doDelete(<%= board.getBoardNo() %>);">삭제</a>&nbsp;]
		        	<% } %>
		        	[&nbsp;<a href="replyform.action?boardno=<%= board.getBoardNo() %>&pageno=<%= pageNo %>">댓글쓰기</a>&nbsp;]
		        	[&nbsp;<a href='list.action?pageno=<%= pageNo %>'>목록보기</a>&nbsp;]
		        </div>
		    </div>
		</div>
	</div>
	</div>
  </div>
</div>



<div id="footer" style=" ;margin-top: 640px; float: inherit">
  <p id="legal">Copyright &copy; 2007 Red Avenue. All Rights Reserved. Designed by <a href="http://www.freecsstemplates.org/">Free CSS Templates</a>.</p>
  <p id="links"><a href="http://www.free-css.com/">Home</a> | <a href="http://www.free-css.com/">Terms of Use</a></p>
</div>
</body>
</html>  

<%-- <!DOCTYPE html>

<html>
<head>

	<meta charset="utf-8" />
	<title>글쓰기</title>
	<link rel="Stylesheet" href="/flappy/styles/default.css" />
	<link rel="Stylesheet" href="/flappy/styles/input2.css" />
	<script type="text/javascript">
	function doDelete(boardno) {
		var ok = confirm("게시물을 삭제 합니다.");
		if (ok) {
			//삭제 처리
			location.href="delete.action?boardno=" + boardno;
		}
	}
	
	function deleteComment(commentNo, boardNo, pageNo) {
		if (confirm(commentNo + "번 댓글을 삭제할까요?")) {
			location.href='deletecomment.action?commentno=' 
				+ commentNo + "&boardno=" + boardNo + "&pageno=" + pageNo;
		}
	}
	
	function toggleCommentStatus(commentNo, edit) {		
		document.getElementById('commentview' + commentNo).style.display = edit ? 'none' : 'block';
		document.getElementById('commentedit' + commentNo).style.display = edit ? 'block' : 'none';
	}
	
	</script>
</head>
<body>

	<div id="pageContainer">
	
		<%
				pageContext.include("/WEB-INF/views/flappy/header.jsp");
			%>
		
		<div style="padding-top:25px;text-align:center">
		<div id="inputcontent">
		    <div id="inputmain">
		        <div class="inputsubtitle">게시판 글 내용</div>
		        <%
		        	Board board = (Board)request.getAttribute("board");
		        %>
		        <table>
		            <tr>
		                <th>제목</th>
		                <td><%=board.getTitle()%></td>
		            </tr>
		            <tr>
		                <th>작성자</th>
		                <td><%=board.getWriter()%></td>
		            </tr>
		            <tr>
		                <th>작성일</th>
		                <td><%=board.getRegDate()%></td>
		            </tr>
					<tr>
		                <th>조회수</th>
		                <td><%=board.getReadCount()%></td>
		            </tr>
		            <tr>
		                <th>내용</th>
		                <td style="height:200px;vertical-align:top">		                    
		                    <%=board.getContent().replace("\r\n", "<br />")%>
		                </td>
		            </tr>
		        </table>
		        <div class="buttons">
		        	<%
		        		String pageNo = request.getParameter("pageno");
		        			        		if (pageNo == null || pageNo.length() == 0)
		        			        			pageNo = "1";
		        	%>
		        	<%
		        		Membership member = (Membership)session.getAttribute("loginuser");
		        	%>
		        	<%
		        		if (member.getMemberId().equals(board.getWriter())) {
		        	%>
		        	[&nbsp;<a href="editform.action?boardno=<%=board.getBoardNo()%>&pageno=<%=pageNo%>">편집</a>&nbsp;]
		        	[&nbsp;<a href="javascript:doDelete(<%=board.getBoardNo()%>);">삭제</a>&nbsp;]
		        	<%
		        		}
		        	%>
		        	[&nbsp;<a href="replyform.action?boardno=<%=board.getBoardNo()%>&pageno=<%=pageNo%>">댓글쓰기</a>&nbsp;]
		        	[&nbsp;<a href='list.action?pageno=<%=pageNo%>'>목록보기</a>&nbsp;]
		        </div>
		    </div>
		</div>
		
		<!-- comment 쓰기 영역 -->
		<br /><br />
		
		로그인 한 사용자만 댓글을 쓸 수 있습니다.
		<%
			if (session.getAttribute("loginuser") != null) {
		%>
		<form id="commentform" 
			action="writecomment.action" method="post">
			<input type="hidden" name="boardno"
				value="<%=board.getBoardNo()%>" />
			<input type="hidden" name="pageno"
				value="<%=pageNo%>" />
			<table style="width:600px;border:solid 1px;margin:0 auto">
	            <tr>
	                <td style="width:550px">
	                	
	                    <textarea name="content" 
	                    	style="width:550px" rows="3"></textarea>
	                    
	                </td>
	                <td style="width:50px;vertical-align:middle">
	                	<a href="javascript:document.getElementById('commentform').submit();"
	                		style="text-decoration:none">
	                		댓글<br />등록
	                	</a>
	                </td>
	            </tr>                    
	        </table>
        </form>
        <%
        	}
        %>
        
                <hr align="center" style="width:600px;" />
        
        <%
                	if (board.getComments().size() == 0) {
                %>
        <h3 id="nodata" style="text-align:center">
            작성된 댓글이 없습니다.
        </h3>
        <%
        	} else {
        %>        
		<!-- comment 표시 영역 -->
		<table style="width:600px;border:solid 1px;margin:0 auto">
		<%
			for(BoardComment bcomment : board.getComments()) {
		%>
        	<tr>
        		<td style="text-align:left;margin:5px;border-bottom: solid 1px">
        		<div id='commentview<%=bcomment.getCommentNo()%>'>
                    <%=bcomment.getWriter()%> &nbsp;&nbsp;
                    [ <%=bcomment.getRegDate()%> ]
                    <br /><br />
                    <span>
                        <%=bcomment.getContent().replace("\r\n", "<br />")%>
                    </span>
                    <br /><br />
                    <div style="display: <%=isCommentEditable((Membership)session.getAttribute("loginuser"), bcomment.getWriter())%>">
                    	<a href="javascript:toggleCommentStatus(<%= bcomment.getCommentNo() %>, true);">편집</a>
                    	&nbsp;
                    	<a href="javascript:deleteComment(<%= bcomment.getCommentNo() %>, <%= board.getBoardNo() %>, <%= pageNo %>)">삭제</a>
                    </div>
                </div>
                
                <div id='commentedit<%= bcomment.getCommentNo() %>' style="display: none">
					<%= bcomment.getWriter() %>&nbsp;&nbsp; 
					[<%= bcomment.getRegDate() %>] 
					<br /><br />
					<form id="commenteditform<%= bcomment.getCommentNo() %>" 
						action="updatecomment.action" method="post">
					<input type="hidden" name="boardno"
						value="<%= board.getBoardNo() %>" />
					<input type="hidden" name="pageno"
						value="<%= pageNo %>" />
					<input type="hidden" name="commentno"
						value="<%= bcomment.getCommentNo() %>" />
					<textarea name="content" style="width: 600px" rows="3" 
						maxlength="200"><%= bcomment.getContent() %></textarea>
					</form>
					<br />
					<div>
						<a href="javascript:document.getElementById('commenteditform<%= bcomment.getCommentNo() %>').submit();">수정</a> 
						&nbsp; 
						<a href="javascript:toggleCommentStatus(<%= bcomment.getCommentNo() %>, false);">취소</a>
					</div>
				</div>
	
				</td>
        	</tr>
        <% } %>
        </table>		
		<% } %>
        
        <br /><br /><br /><br /><br /><br />
	
	</div>
	</div>

</body>
</ht --%>